﻿using System;
using System.Windows.Forms;

namespace common
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //ServiceController sc = new ServiceController("UPnP Device Host");

            ////Console.WriteLine("The Telnet service status is currently set to {0} ", sc.Status.ToString());

            //if ((sc.Status.Equals(ServiceControllerStatus.Stopped)) || (sc.Status.Equals(ServiceControllerStatus.StopPending)))
            //{                // Start the service if the current status is stopped.
            //    //MessageBox.Show("Starting the Telnet service... ");
            //    sc.Start();
            //}

            ////sc = new ServiceController("SSDP Discovery Service");
            ////if ((sc.Status.Equals(ServiceControllerStatus.Stopped)) || (sc.Status.Equals(ServiceControllerStatus.StopPending)))
            ////{                // Start the service if the current status is stopped.
            ////    Console.WriteLine("Starting the Telnet service... ");
            ////    sc.Start();
            ////}

            common.net.Router r = new net.Router();
            string all = r.getWanIP();
            //this.richTextBox1.Text = r.getWanIP();

            int start = all.IndexOf("wanPara") + 1;
            var tempip = all.Substring(start, 100);

            //var ss = Regex.Match(tempip, @"^\d+.\d+.\d+.\d+$");

            var s1 = tempip.Replace("\"", "");
            foreach (var item in s1.Split('\n'))
            {
                //System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(item, @"^\d+\.\d+\.\d+\.\d+$");
                System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(item, @"\d+\.\d+\.\d+\.\d+");

                if (m.Success)
                {
                    this.richTextBox1.Text = m.Value;
                    return;
                }
            }

            //System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(tempip.Replace("\"",""), @"^\d+\.\d+\.\d+\.\d+$");
            //var s= m.Value.Trim();

            //var rr = new Regex(@"^\d+.\d+.\d+.\d+$");

            //HttpContextBase httpContext=new
            //common.net.IPHelper r = new net.IPHelper();
            //this.richTextBox1.Text = r.GetIpAddress();
        }
    }
}